package com.jy.project.config;

import cn.hutool.core.io.FileTypeUtil;
import cn.hutool.core.io.FileUtil;
import com.jy.project.inter.LoginInterceptor;
import com.jy.project.inter.RoleInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.ArrayList;
import java.util.List;

/*
 *静态资源不拦截
 *
 */
@Configuration
public class MvcInterceptorConfig extends WebMvcConfigurationSupport {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Autowired
    private RoleInterceptor roleInterceptor;


    public static  final  boolean IS_BUG=false;
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        // 多个拦截器组成一个拦截器链
        // addPathPatterns 用于添加拦截规则，/**表示拦截所有请求
        // excludePathPatterns 用户排除拦截
        if (IS_BUG==false) {
            List<String> excludeUrls = new ArrayList<>();
            excludeUrls.add("/static/**");
            registry.addInterceptor(loginInterceptor)
                    .addPathPatterns("/v1/**")
                    .excludePathPatterns(excludeUrls);

           /* registry.addInterceptor(roleInterceptor)
                    .addPathPatterns("/v1/**")
                    .excludePathPatterns(excludeUrls);*/
        }
        super.addInterceptors(registry);
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }

}
